package com.aitou.mrylive.presentation.ui.room.create;

import android.content.Context;

import com.aitou.mrylive.util.share.ShareHelper;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import rx.functions.Func1;

/**
 * @author Muyangmin
 * @since 1.0.0
 */
public class CreateRoomShareHelper extends ShareHelper {

    private ShareParamProvider provider;
    private PlatformActionListener listener;

    public CreateRoomShareHelper(Context context, String roomId, String anchorName,String imgUrl,
                                 PlatformActionListener listener) {
        provider = new RoomShareParam(context, roomId, anchorName,imgUrl);
        this.listener = listener;
    }

    public void share(Platform platform){
        invokeShare(platform.getName(), listener, parseParam(platform));
    }

    private Func1<Void, ? extends Platform.ShareParams> parseParam(Platform platform){
        if (platform instanceof QQ){
            return new QQParamBuilder(provider);
        }
        else if (platform instanceof QZone){
            return new QZoneParamBuilder(provider);
        }
        else if (platform instanceof Wechat){
            return new WechatParamBuilder(provider);
        }
        else if (platform instanceof WechatMoments){
            return new WechatParamBuilder(provider);
        }
        else if (platform instanceof SinaWeibo){
            return new SinaWeiboParamBuilder(provider);
        }
        throw new IllegalArgumentException("Unsupported platform!");
    }
}
